package kyleUtil.dateFormat;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author kyle
 * @version 1.0
 * @date 2021/4/7 14:41
 */
public class TimeRecorder{
    Date beginDate;
    Date endDate;
    public static void main(String[] args) {

    }
    public void beginRecord(){
        beginDate = new Date();
    }
    public void endRecord(){
        endDate = new Date();
    }
    public String gettimeBetween(){
        long between = endDate.getTime() - beginDate.getTime();
        long day = between / (24 * 60 * 60 * 1000);
        long hour = (between / (60 * 60 * 1000) - day * 24);
        long min = ((between / (60 * 1000)) - day * 24 * 60 - hour * 60);
        long s = (between / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
        return day + "天" + hour + "小时" + min + "分" + s + "秒";
    }

    public void print(){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("hh:mm:ss");
        String beginFormmated = simpleDateFormat.format(beginDate);
        String endFormatted = simpleDateFormat.format(endDate);




        System.out.println("执行起始时间:"+beginFormmated);
        System.out.println("结束时间:"+endFormatted);
        System.out.println("用时:"+gettimeBetween());
    }
}
